package com.example.teamwork.converter;

import com.example.teamwork.informationGet.InterVo;
import com.example.teamwork.mapper.PartMapper;
import com.example.teamwork.pojo.Inter;
import com.example.teamwork.pojo.Part;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author  SongPeng
 * @date  2021/11/10 14:22
 * @version 1.0
 */

@Component
public class InterConverter {
    @Autowired
    private PartMapper departmentMapper;

    /**
     * 转voList
     * @param inters
     * @return
     */
    public  List<InterVo> converterToInterVOList(List<Inter> inters){
        List<InterVo> interVos=new ArrayList<>();
        if(!CollectionUtils.isEmpty(inters)){
            for (Inter inter : inters) {
                InterVo interVo = converterToInterVO(inter);
                interVos.add(interVo);
            }
        }
        return interVos;
    }

    /**
     * 转vo
     * @return
     */
    public  InterVo converterToInterVO(Inter inter){
        InterVo interVo = new InterVo();
        BeanUtils.copyProperties(inter,interVo);
        Part department = departmentMapper.selectByPrimaryKey(inter.getPartId());
        if(department!=null&&department.getPartName()!=null){
            interVo.setPartName(department.getPartName());
            interVo.setPartId(department.getPartId());
        }

        return interVo;
    }

}

